package com.clqteam.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.clqteam.model.Employee;
import com.clqteam.service.ShowTempOrderService;
import com.clqteam.serviceimpl.ShowTempOrderServiceImpl;

public class DelWholeSaleProController extends HttpServlet{

	ShowTempOrderService stoSer = new ShowTempOrderServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		req.setCharacterEncoding("UTF8");
		resp.setCharacterEncoding("UTF8");
		
		HttpSession session = req.getSession();
		Employee e = (Employee)session.getAttribute("employee");
		int eId = e.geteId();
		String tbName = "s_WholeSaleOrder_"+eId;
		
		String[] pIds = req.getParameterValues("ids");
		int flags = 0;
		for (int i = 0; i < pIds.length; i++) {
			int pId = Integer.parseInt(pIds[i]);	
			int flag = stoSer.deleteTempOrderInfoByPId(pId,tbName);
			if(flag>0){
				flags++;
			}
		}
		PrintWriter pw =resp.getWriter();
		if(flags == pIds.length){
			pw.write("1");
		}else{
			pw.write("0");
		}
		pw.flush();
		pw.close();
		
	}
	
}
